<?php 
/**
* 
*/
class KhachhangController extends Controller
{
	
	public function actionIndex()
	{
		$this->render('index');
	}
	public function actionCreateCustomer(){
		$this->_checkAuth();
		if($this->checkRoleBase()){
			$form_data = json_decode(file_get_contents('php://input'));
			$model = new Account;
			foreach($form_data as $var=>$value) {
				if($model->hasAttribute($var)) {
                    $model->$var = $value;
                } else {
                    // No, raise an error
                    $this->_sendResponse(500, sprintf('Parameter <b>%s</b> is not allowed for model <b>%s</b>', $var, $_GET['model']) );
                }
			}
			if($model->save()) {
            // Saving was OK
            // $this->_sendResponse(200, $this->_getObjectEncoded($_GET['model'], $model->attributes) );
            	echo json_encode(array("success" => true,'id'=>$model->id));
	        } else {
	        	$this->_sendResponse(500, 'Create new customer fail' );
	        }
		}
	}
}